﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    /// <summary>
    /// 删除数据源和数据表的映射关系,并删除数据表
    /// </summary>
    [CPPEI.WebApi.AuthPostAction("DtSer", "DeleteTable", "1.0")]
    public class DeleteTableAction : BaseAction<DeleteTableParams, DeleteTableResult>
    {
        protected override ActionResult<DeleteTableResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            DeleteTableParams opParams)
        {
            Logger.DebugToTag(Library.LogTAG, "DtSer:DeleteTable");

            SER.DeleteService service = new SER.DeleteService();
            ServiceResult result = service.DeleteDataTableAndMapping(context.UserId, opParams.DataServiceId, opParams.DataSourceId, opParams.DataTableId);
            if(result.IsSuccess)
            {
                return new ActionResult<DeleteTableResult>(new DeleteTableResult());
            }
            else
            {
                return new ActionResult<DeleteTableResult>(result.IsSuccess, result.ErrorCode, result.Message, null);
            }
        }
    }

    public class DeleteTableParams
    {
        public Guid DataServiceId { get; set; }
        public Guid DataSourceId { get; set; }
        public Guid DataTableId { get; set; }
    }

    public class DeleteTableResult
    {
    }
}
